<template>
    <div>
    <div class="goodslist">
        <div class="goodsitem" v-for="item in goodslist" :key="item.id" @click="goDetail(item.id)">
            <img :src="item.img_url" alt="">
            <div class="title">
                {{item.title}}
            </div>
            <div class="info">
                <p class="price">
                    <span class="now">{{item.sell_price}}</span>
                    <span class="old">{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span >热卖中</span>
                    <span >剩{{stock_quantity}}件</span>
                </p>
            </div>
        </div>
         <mt-button type="danger" size="large"   @click="getmore">加载更多</mt-button>
    </div>
    </div>
</template>
<script>
import {Toast} from 'mint-ui'
export default{
    data(){
        return{
            pageindex:1,
            goodslist:[]
        }
    },
    created(){
        this.getGoodsList()
    },
    methods:{
        getGoodsList(){
            this.$http.get('api/getgoods?pageindex='+this.pageindex).then(result=>{
                if(result.body.status==0){
                    this.goodslist=this.goodslist.concat(result.body.message);
                }
                else{
                    Toast('商品列表加载失败')
                }
            })
        },
        getmore(){
            this.pageindex++;
            this.getGoodsList();
        },
        goDetail(id){
        //     this.$route是路由中的参数对象,params,query都属于它
        //    this.$router是路由中的导航对象,用它可以方便的使用JS代码,实现 路由的前进,
        //    后退,跳转到新的URL地址
            //最简单的
           // this.$router.push('/home/goodsinfo/'+id)
           //传递对象
           // this.$router.push({ path: '/home/goodsinfo/'+id })
           //传递命名的路由
           this.$router.push({ name: 'goodsinfo', params: { id }})
        }
    }
}
</script>
<style lang="scss" scoped>
.goodslist{
    padding: 7px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .goodsitem{
         width: 49%;
         border: 1px solid #ccc;
         box-shadow: 0 0 8px #ccc;
         margin: 4px 0;
         padding: 2px;
         display: flex;
         flex-direction: column;
         justify-content: space-between;
         min-height: 293px;
        .title{

            font-size: 14px;        
        }
        img{
            width:100%;
        }
        .info{
            background-color: #eee;
           
            .price{
                .now{
                    font-size: 18px;
                    color: red;
                    font-weight: bold;
                }
                .old{
                    text-decoration:line-through;
                    font-size: 12px;
                    margin-left: 10px;
                }
            }
            .sell{
                display: flex;
                justify-content: space-between;
                font-size: 13px;
            }

        }
    }
}
</style>
